package com.module.shici.sql;

import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;

import com.fenghuajueli.libbasecoreui.BaseApplication;

@Database(entities = {ShiCi.class,Author.class},version = 1, exportSchema = false)
public abstract class ShiCiDataBase extends RoomDatabase {

    private static final String DB_NAME = "shici.db";
    private static volatile ShiCiDataBase instance;

    public static synchronized ShiCiDataBase getInstance() {
        if (instance == null) {
            instance = create();
        }
        return instance;
    }

    private static ShiCiDataBase create() {
        return Room.databaseBuilder(
                BaseApplication.getApplication(),
                ShiCiDataBase.class,
                DB_NAME)
                .createFromAsset("shici.db")//从assets复制
                .allowMainThreadQueries()//允许在主线程允许
                .build();
    }

    public abstract ShiCiDao getShiCiDao();
}
